package com.umeng.analytics.pro;

import android.content.Context;

import com.umeng.analytics.a;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.security.MessageDigest;
import java.util.Locale;
import java.util.Random;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

public class bt {
    private static final byte[] a = new byte[]{10, 1, 11, 5, 4, 15, 7, 9, 23, 3, 1, 6, 8, 12, 13, 91};

    public bt() {

    }

    public static String a(Throwable arg4) {
        String v0 = null;
        if (arg4 != null) {
            try {
                StringWriter v2 = new StringWriter();
                PrintWriter v3 = new PrintWriter(((Writer) v2));
                arg4.printStackTrace(v3);
                Throwable v1_1;
                for (v1_1 = arg4.getCause(); v1_1 != null; v1_1 = v1_1.getCause()) {
                    v1_1.printStackTrace(v3);
                }

                v0 = v2.toString();
                v3.close();
                ((Writer) v2).close();
            } catch (Exception v1) {
                v1.printStackTrace();
            }
        }

        return v0;
    }

    public static String a(byte[] arg6) {
        String v0;
        if (arg6 == null) {
            v0 = null;
        } else {
            StringBuffer v2 = new StringBuffer();
            int v0_1;
            for (v0_1 = 0; v0_1 < arg6.length; ++v0_1) {
                v2.append(String.format("%02X", Byte.valueOf(arg6[v0_1])));
            }

            v0 = v2.toString().toLowerCase(Locale.US);
        }

        return v0;
    }

    public static byte[] a(String arg6) {
        byte[] v0 = null;
        if (arg6 != null) {
            int v2 = arg6.length();
            if (v2 % 2 == 0) {
                v0 = new byte[v2 / 2];
                int v1;
                for (v1 = 0; v1 < v2; v1 += 2) {
                    v0[v1 / 2] = ((byte) Integer.valueOf(arg6.substring(v1, v1 + 2), 16).intValue());
                }
            }
        }

        return v0;
    }

    public static byte[] a(byte[] arg4, byte[] arg5) throws Exception {
        Cipher v0 = Cipher.getInstance("AES/CBC/PKCS7Padding");
        v0.init(1, new SecretKeySpec(arg5, "AES"), new IvParameterSpec(bt.a));
        return v0.doFinal(arg4);
    }

    public static boolean a(Context arg7, byte[] arg8) {
        boolean v0;
        long v2 = ((long) arg8.length);
        if (v2 > com.umeng.analytics.a.y) {
            cc.a(arg7).g();
            m.a(arg7).a(v2, System.currentTimeMillis(), "__data_size_of");
            v0 = true;
        } else {
            v0 = false;
        }

        return v0;
    }

    public static int a(int arg6, String arg7) {
        int v0 = 0;
        if ((((double) new Random().nextFloat())) < 0.001) {
            if (arg7 == null) {
                by.c("--->", new Object[]{"null signature.."});
            }

            int v1 = 9;
            int v2 = 11;
            try {
                v0 = Integer.parseInt(arg7.substring(v1, v2), 16);
            } catch (Exception v1_1) {
            }

            return (v0 | 128) * 1000;
        }

        v0 = new Random().nextInt(arg6);
        if (v0 <= 255000 && v0 >= 128000) {
            v0 = 127000;
        }

        return v0;
    }

    public static byte[] b(byte[] arg1) {
        byte[] v0_2;
        try {
            MessageDigest v0_1 = MessageDigest.getInstance("MD5");
            v0_1.reset();
            v0_1.update(arg1);
            v0_2 = v0_1.digest();
        } catch (Exception v0) {
            v0.printStackTrace();
            v0_2 = null;
        }

        return v0_2;
    }

    public static String b(String arg3) {
        return "http://" + arg3 + ".umeng.com/app_logs";
    }

    public static byte[] b(byte[] arg4, byte[] arg5) throws Exception {
        Cipher v0 = Cipher.getInstance("AES/CBC/PKCS7Padding");
        v0.init(2, new SecretKeySpec(arg5, "AES"), new IvParameterSpec(bt.a));
        return v0.doFinal(arg4);
    }

    public static String c(String arg2) {
        String v0_2;
        byte[] v0 = arg2.getBytes();
        try {
            MessageDigest v1 = MessageDigest.getInstance("SHA1");
            v1.update(v0);
            v0_2 = bt.c(v1.digest());
        } catch (Exception v0_1) {
            v0_2 = null;
        }

        return v0_2;
    }

    static String c(byte[] arg6) {
        String v0 = "";
        int v1 = 0;
        while (v1 < arg6.length) {
            String v2 = Integer.toHexString(arg6[v1] & 255);
            if (v2.length() == 1) {
                v0 = v0 + "0";
            }

            ++v1;
            v0 = v0 + v2;
        }

        return v0;
    }
}

